var t = getApp(), a = require("../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ a ],
    data: {
        navStatus: [ {
            title: "全部",
            status: "",
            url: ""
        }, {
            title: "未结算",
            status: "0",
            url: "plugin.ecological-point.frontend.modules.tactful.controllers.records.index"
        }, {
            title: "已结算",
            status: "1",
            url: "plugin.ecological-point.frontend.modules.tactful.controllers.records.index"
        }, {
            title: "已失效",
            status: "-1",
            url: "plugin.ecological-point.frontend.modules.tactful.controllers.records.index"
        } ],
        teamAgentNav: [ {
            title: "团队奖励",
            status: 1,
            url: "plugin.ecological-point.frontend.modules.team.controllers.reward.reward-list"
        }, {
            title: "团队招商奖励",
            status: 2,
            url: "plugin.ecological-point.frontend.modules.team.controllers.reward.merchant-reward-list"
        }, {
            title: "加权分红奖励",
            status: 3,
            url: "plugin.ecological-point.frontend.modules.team.controllers.reward.weight-reward-list"
        } ],
        areaNav: [ {
            title: "区域奖励",
            status: 1,
            url: "plugin.ecological-point.frontend.modules.area.controllers.reward.reward-list"
        }, {
            title: "加权分红奖励",
            status: 2,
            url: "plugin.ecological-point.frontend.modules.area.controllers.reward.weight-reward-list"
        } ],
        nowStatus: "",
        teamStatus: 1,
        areaStatus: 1,
        status: null,
        info: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        t.status && this.setData({
            status: t.status
        }), this.setData({
            nowStatus: "",
            teamStatus: 1,
            areaStatus: 1
        }), this.getData(), this.checkTitle();
    },
    tapStatusNav: function(t) {
        var a = t.currentTarget.dataset.item, s = t.currentTarget.dataset.key;
        "1" == s ? this.setData({
            nowStatus: a
        }) : "2" == s ? (this.setData({
            areaStatus: a
        }), this.nowStatus = "") : "3" == s && (this.setData({
            teamStatus: a
        }), this.nowStatus = ""), this.init(), this.getData();
    },
    init: function() {
        this.setData({
            info: [],
            page: 1,
            total_page: 0,
            isLoadMore: !0
        });
    },
    checkTitle: function() {
        1 != this.data.status ? 2 != this.data.status ? 3 != this.data.status || wx.setNavigationBarTitle({
            title: "区域奖励"
        }) : wx.setNavigationBarTitle({
            title: "经销商奖励"
        }) : wx.setNavigationBarTitle({
            title: "让利奖励"
        });
    },
    getData: function() {
        var a = this, s = "", e = {};
        e.page = this.data.page, 2 == this.data.status ? (e.status = this.data.nowStatus ? this.data.nowStatus : "", 
        s = this.data.teamAgentNav[this.data.teamStatus - 1].url, 3 == this.data.teamStatus && (e.status = "")) : 3 == this.data.status ? (e.status = this.data.nowStatus ? this.data.nowStatus : "", 
        s = this.data.areaNav[this.data.areaStatus - 1].url, 2 == this.data.areaStatus && (e.status = "")) : (s = "plugin.ecological-point.frontend.modules.tactful.controllers.records.index", 
        "" == this.data.nowStatus ? e.status = "0" : "0" == this.data.nowStatus ? e.status = "1" : "1" == this.data.nowStatus ? e.status = "2" : "-1" == this.data.nowStatus && (e.status = "-1"));
        var o = t.getNetAddresss(s);
        t._postNetWork({
            url: o,
            data: e,
            success: function(t) {
                var s = t.data;
                1 == s.result ? (a.data.isLoadMore = !0, 1 == a.data.status ? a.setData({
                    info: s.data.data,
                    total_page: s.data.last_page
                }) : a.setData({
                    info: s.data.list.data,
                    total_page: s.data.list.last_page
                }), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: a.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                })) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (this.data.isLoadMore) {
            if (this.data.page >= this.data.total_page) return;
            console.log(this.data.isLoadMore, this.data.total_page, this.data.page, "ddddddddddd"), 
            this.getMoreData();
        }
    },
    onShareAppMessage: function() {},
    getMoreData: function() {
        var a = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.setData({
                page: Number(this.data.page) + 1
            });
            var s = "", e = {};
            e.page = this.data.page, 2 == this.data.status ? (e.status = this.nowStatus, s = this.data.teamAgentNav[this.data.teamStatus - 1].url, 
            3 == this.data.teamStatus && (e.status = "")) : 3 == this.data.status ? (e.status = this.data.nowStatus, 
            s = this.data.areaNav[this.data.areaStatus - 1].url, 2 == this.data.areaStatus && (e.status = "")) : (s = "plugin.ecological-point.frontend.modules.tactful.controllers.records.index", 
            "" == this.data.nowStatus ? e.status = "0" : "0" == this.data.nowStatus ? e.status = "1" : "1" == this.data.nowStatus ? e.status = "2" : "-1" == this.data.nowStatus && (e.status = "-1"));
            var o = t.getNetAddresss(s);
            t._postNetWork({
                url: o,
                data: e,
                success: function(t) {
                    var s = t.data;
                    if (1 == s.result) {
                        a.data.isLoadMore = !0;
                        var e = "";
                        e = 1 == a.data.status ? s.data.data : s.data.list.data, a.setData({
                            info: a.data.info.concat(e)
                        });
                    } else wx.showToast({
                        icon: "none",
                        title: s.msg,
                        duration: 1e3
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    }
});